<template>

  <div class="views-container">
      <el-dialog  custom-class="wlm-form-dialog dialog-table" :visible.sync="dialogTableVisible"  width="50%">
                   <div  class="wlm-form">
              <div class="wlm-form-header wlm-dialog-fixheader">
              <span class="wlm-dialog-inlenr">修改状态</span>
            </div>
             <el-scrollbar wrap-class="scrollbar-wrapper">
        <div class="wlm-form-content">
          <div class="wlm-dialog-main">
            <div class="wlm-dialog-content" >
            <div style="display:flex;align-items: center;">
                <div style="margin-right:20px;">修改状态</div>
                <el-radio-group v-model.trim="recharge_status" >
                  <el-radio :label="2">成功</el-radio>
                </el-radio-group>
            </div>
            </div>
          </div>
        </div>
             </el-scrollbar>
            </div>
            <footer class="flex-row flex-align-c flex-justify-c wlm-dialog-fixfooter">
              <el-button size="small" @click="handsave" type="primary">保存</el-button>
            </footer>
  </el-dialog>
    <div class="wlm-table">
      <!-- 工具条区域 -->
      <div class="wlm-table-header">
        <el-form
          :model="tableFormatData.mainTable.files"
          size="small"
          label-width="80px"
          class="retail-form"
          label-position="right"
        >
          <el-form-item class="filter">
            <el-form-item label="充值号码：">
              <el-input
                @keyup.enter.native="filesSerch"
                v-model="tableFormatData.mainTable.files.recharge_phone"
                placeholder="请输入充值号码"
                style="width: 160px"
              ></el-input>
            </el-form-item>
          </el-form-item>
          <el-form-item label class="filter-btns">
            <el-button v-waves type="primary" @click="filesSerch"
              >筛选</el-button
            >
            <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
          </el-form-item>
        </el-form>
      </div>
      <!-- 工具条区域 end -->
      <!-- 表格区域 -->
      <div class="wlm-table-content">
        <el-table
          :ref="tableFormatData.mainTable.key"
          :default-sort="{ prop: 'sort', order: 'descending' }"
          :data="tableFormatData.mainTable.tableData"
          @selection-change="handleSelectionChange"
          style="width: 100%"
        >
          <el-table-column prop="order_no" label="订单号" width="160" />
          <el-table-column prop="name" label="用户信息">
            <template slot-scope="scope">
              <el-row type="flex" align="middle" :gutter="8">
                <el-col style="width: auto">
                  <el-avatar
                    size="medium"
                    :src="scope.row.avatarUrl"
                  ></el-avatar>
                </el-col>
                <el-col style="width: auto">
                  <span>{{ scope.row.nickName }}</span>
                </el-col>
              </el-row>
            </template>
          </el-table-column>
          <el-table-column prop="recharge_phone" label="充值号码" width="120" />
          <el-table-column prop="recharge_type" label="充值方式">
            <template slot-scope="scope">
              <el-tag
                v-if="scope.row.recharge_type == 1"
                type="success"
                size="small"
                >快充</el-tag
              >
              <el-tag
                v-if="scope.row.recharge_type == 2"
                type="info"
                size="small"
                >慢充</el-tag
              >
            </template>
          </el-table-column>
          <el-table-column prop="amount" label="充值金额" />
          <el-table-column prop="pay_price" label="支付金额" />
          <el-table-column prop="coupon_money" label="优惠券抵扣" />
          <el-table-column prop="vip_coupon_money" label="会员优惠" />
          <el-table-column prop="order_time" label="下单时间" width="200" />
          <el-table-column prop="pay_time" label="支付时间" width="200" />
          <el-table-column prop="pay_status" label="支付状态">
            <template slot-scope="scope">
              <el-tag v-if="scope.row.pay_status == 10" type="info" size="small"
                >未付款</el-tag
              >
              <el-tag
                v-else-if="scope.row.pay_status == 20"
                type="success"
                size="small"
                >已付款</el-tag
              >
              <el-tag
                v-else-if="scope.row.pay_status == 30"
                type="danger"
                size="small"
                >已退款</el-tag
              >
            </template>
          </el-table-column>
          <el-table-column prop="recharge_status" label="充值状态">
            <template slot-scope="scope">
              <el-tag
                v-if="scope.row.recharge_status == 1"
                type="info"
                size="small"
                >未充值</el-tag
              >
              <el-tag
                v-else-if="scope.row.recharge_status == 2"
                type="success"
                size="small"
                >已充值</el-tag
              >
              <el-tag
                v-else-if="scope.row.recharge_status == 3"
                type="danger"
                size="small"
                >充值失败</el-tag
              >
              <el-tag
                v-else-if="scope.row.recharge_status == 4"
                type="warning"
                size="small"
                >充值中</el-tag
              >
            </template>
          </el-table-column>
          <el-table-column label="操作" min-width="120">
            <template slot-scope="scope">
          <div style="display:flex;">
                <el-button
                type="danger"
                size="mini"
                :loading="scope.row.refundLoading"
                v-if="scope.row.pay_status == 20"
                @click="handleBtnRefundClick(scope)"
                >退款</el-button>
                <el-button type="text" style="margin-left:10px;" @click="handbutton(scope.row.id)" v-if="scope.row.pay_status == 20">修改状态</el-button>
          </div>
            </template>
          </el-table-column>
        </el-table>
        <div class="pagination-content flex-row flex-justify-e flex-align-c">
          <el-pagination
            :disabled="!hasTableData"
            @size-change="listPageChange"
            @current-change="listPageChange"
            :current-page.sync="tableFormatData.mainTable.pagination.page"
            :page-sizes="tableFormatData.mainTable.pagination.pagesizes"
            :page-size.sync="tableFormatData.mainTable.pagination.list_rows"
            layout="total, sizes, prev, pager, next, jumper"
            :total="
              hasTableData ? tableFormatData.mainTable.pagination.total : 0
            "
          ></el-pagination>
        </div>
      </div>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>

<script>
import fp from "lodash/fp";
import { phoneOrderLists, phoneOrderRefund,phoneOrderStatus } from "@/api/phoneBill";
import mixins from "@/mixins/mixins";
import ChooseFiles from "@/components/ChooseFiles/index";
import waves from "@/directive/waves";
export default {
  mixins: [mixins.getters("Table")],
  components: {
    ChooseFiles,
  },
  directives: {
    waves,
  },
  data() {
    return {
      // 卡信息列表的数据
      id:'',
      dialogTableVisible:false,
      cardCate: [],
      recharge_status:2,
      tableFormatData: {
        current: "mainTable",
        mainTable: {
          key: "mainTable",
          api: {
            getList: phoneOrderLists,
            change: {
              phoneOrderRefund: {
                key: "phoneOrderRefund",
                api: phoneOrderRefund,
              },
            },
          },
          tableData: [],
          files: {
            recharge_phone: "",
          },
          rowId: "card_order_id",
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0,
          },
        },
      },
    };
  },
  methods: {
    handbutton(id){
      this.id = id
      // this.recharge_status = recharge_status_id
      this.dialogTableVisible = true

      
    },
    handsave(){
      phoneOrderStatus({id:this.id,recharge_status:this.recharge_status}).then(res=>{
        if(res.data.code==1){
          // recharge_status
          console.log("5555555555555",res)
          this.$message.success("保存成功！")
          this.dialogTableVisible = false
          this.filesSerch()
        }
      }).finally(()=>{
        this.dialogTableVisible = false
      })
    },
    showdialog(type, params) {
      if (type === 1) {
        // this.formFormatData=[]
        this.formFormatData.api.submitForm = cardClassSave;
        this.dialogFormVisible = true;
      }
      if (type === 2) {
        this.formFormatData.api.submitForm = cardClassSave;
        this.formFormatDialogEditEvt({
          id: params,
          toggle: "dialogFormVisible",
        });
      }
    },
    saveDialogForm() {
      this.resetDialogFormData({
        name: "",
        sort: "",
        is_show: "",
        image: [],
      });
    },
    handleBtnRefundClick(scope) {
      if (scope.row.refundLoading) return;

      this.$confirm("是否确定退款", "注意", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          const index = fp.findIndex(
            (item) => item.id === scope.row.id,
            this.tableFormatData.mainTable.tableData
          );
          this.tableFormatData.mainTable.tableData = fp.set(
            `[${index}].refundLoading`,
            true,
            this.tableFormatData.mainTable.tableData
          );
          const row = fp.get(index, this.tableFormatData.mainTable.tableData);

          phoneOrderRefund({
            id: scope.row.id,
          })
            .then(() => {
              this.$message({
                message: "操作成功",
                type: "success",
              });
              this.getTableList();
            })
            .catch(() => {})
            .finally(() => {
              row.refundLoading = false;
            });
        })
        .catch(() => {});
    },
  },
};
</script>

<style lang="scss" scoped>
</style>